package com.ruoyi.sgsc.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.sgsc.domain.cartitems;
import com.ruoyi.sgsc.service.IcartitemsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 购物车详情Controller
 * 
 * @author wy
 * @date 2024-09-29
 */
@Anonymous
@RestController
@RequestMapping("/sgsc/cartitems")
public class cartitemsController extends BaseController
{
    @Autowired
    private IcartitemsService cartitemsService;

    /**
     * 查询购物车详情列表
     */

    @GetMapping("/list")
    public TableDataInfo list(cartitems cartitems)
    {
        startPage();
        List<cartitems> list = cartitemsService.selectcartitemsList(cartitems);
        return getDataTable(list);
    }

    /**
     * 导出购物车详情列表
     */

    @PostMapping("/export")
    public void export(HttpServletResponse response, cartitems cartitems)
    {
        List<cartitems> list = cartitemsService.selectcartitemsList(cartitems);
        ExcelUtil<cartitems> util = new ExcelUtil<cartitems>(cartitems.class);
        util.exportExcel(response, list, "购物车详情数据");
    }

    /**
     * 获取购物车详情详细信息
     */

    @GetMapping(value = "/{cartitemId}")
    public AjaxResult getInfo(@PathVariable("cartitemId") Long cartitemId)
    {
        return success(cartitemsService.selectcartitemsByCartitemId(cartitemId));
    }

    /**
     * 新增购物车详情
     */

    @PostMapping
    public AjaxResult add(@RequestBody cartitems cartitems)
    {
        return toAjax(cartitemsService.insertcartitems(cartitems));
    }

    /**
     * 修改购物车详情
     */

    @PutMapping
    public AjaxResult edit(@RequestBody cartitems cartitems)
    {
        return toAjax(cartitemsService.updatecartitems(cartitems));
    }

    /**
     * 删除购物车详情
     */

	@DeleteMapping("/{cartitemIds}")
    public AjaxResult remove(@PathVariable Long[] cartitemIds)
    {
        return toAjax(cartitemsService.deletecartitemsByCartitemIds(cartitemIds));
    }

    /**
     * 根据商品id删除购物车详情
     * @param productId
     * @return
     */
    @DeleteMapping("/cartitems/{productId}")
    public AjaxResult removeByProductId(@PathVariable Long productId)
    {
        return toAjax(cartitemsService.deletecartitemsByProductId(productId));
    }
}
